package com.gitee.huxing.course.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.config
 * @ClassName: DataSourceHikariConfig
 * @Author: huxing
 * @DateTime: 2021-09-05 上午11:00
 */
@Profile("hikari")
@Configuration
public class DataSourceHikariConfig {

    @Primary
    @Bean("myJdbcTemplate")
    public JdbcTemplate create(@Qualifier("dataSource")DataSource dataSource){
        return new JdbcTemplate(dataSource);
    }

    @Bean("myConnection")
    public Connection getConnection(@Qualifier("dataSource")DataSource dataSource) throws SQLException {
        return dataSource.getConnection();
    }
}
